/*******************************************************************************
 * Copyright (c) 2006 CEA List.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     CEA List - initial API and implementation
 *******************************************************************************/
package com.cea.papyrus.diagram.usecase.figure;

import org.eclipse.draw2d.Graphics;
import org.eclipse.draw2d.ToolbarLayout;
import org.eclipse.draw2d.geometry.Point;
import org.eclipse.draw2d.geometry.Rectangle;
import org.eclipse.swt.SWT;
import org.eclipse.uml2.uml.Element;

import com.cea.papyrus.core.figures.NodeFigure;
import com.cea.papyrus.core.utils.Debug;
import com.cea.papyrus.diagraminterchange2.di2.GraphElement;

/**
 * Defines the view of a use case displayed as an ellipse
 * with the name outside.
 * 
 * @author Gilles Cannenterre
 * @since 28 nov. 06
 */
public class UseCaseEllipseFormNameOutsideFigure extends UseCaseEllipseGeneralFigure {

	/**
	 * The Class UseCaseContainerFigure.
	 * Holds the extension points.
	 */
	protected class UseCaseContainerFigure extends NodeFigure {
	
		/**
		 * The Constructor.
		 */
		public UseCaseContainerFigure() {
			super();
			Debug.debug(this, "ContainerFigure()", channel);
			ToolbarLayout layout = new ToolbarLayout(ToolbarLayout.VERTICAL); // vertically
			layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
			layout.setSpacing(2);
			setLayoutManager(layout);
		}
	
	}

	
	/**
	 * The Constructor.
	 */
	public UseCaseEllipseFormNameOutsideFigure() {
		super();
		ToolbarLayout layout = new ToolbarLayout();
		setLayoutManager(layout);
		containerFigure = new UseCaseContainerFigure();
		add(containerFigure);
	}

	/**
	 * Paint border.
	 * 
	 * @param graphics the graphics
	 */
	@Override
	public void paintBorder(Graphics graphics) {

	}

	/**
	 * Sets the name.
	 * 
	 * @param name the name
	 */
	@Override
	public void setName(String name) {}

	/**
	 * Sets the qualified name.
	 * 
	 * @param qualifiedName the qualified name
	 */
	@Override
	public void setQualifiedName(String qualifiedName) {}

	/**
	 * Sets the stereotypes.
	 * 
	 * @param stereotypes the stereotypes
	 */
	@Override
	public void setStereotypes(String stereotypes) {}

	/**
	 * Refresh colors.
	 * 
	 * @param graphElement the graph element
	 */
	@Override
	public void refreshColors(GraphElement graphElement) {
		super.refreshColors(graphElement);		
		setForegroundColor(getBorderColor());
	}

	/**
	 * Paint figure.
	 * 
	 * @param graphics the graphics
	 */
	@Override
	public void paintFigure(Graphics graphics) {
		graphics.setAntialias(SWT.ON);
		Rectangle rect = getBounds();
		graphics.fillOval(new Rectangle(rect.x + 1, rect.y + 1, rect.width - 2,
				rect.height - 2));
		graphics.setLineWidth(1);
		graphics.drawOval(new Rectangle(rect.x + 1, rect.y + 1, rect.width - 2,
				rect.height - 2));
	}

	/**
	 * Refresh presentation.
	 * 
	 * @param presentation the presentation
	 * @param selection the selection
	 */
	@Override
	public void refreshPresentation(String presentation, Element selection, GraphElement ge) {}

	/**
	 * Sets the bounds of the figure and its children.
	 * 
	 * @param rect the rect
	 */
	@Override
	public void setBounds(Rectangle rect) {
		Debug.debug(this, "setBounds(Rectangle)", channel);
		if (extensionPointContent != null) {
			extensionPointContent.setLocation(new Point(0, rect.height 
					- (int)(rect.height/2)));
			extensionPointContent.setPreferredSize(rect.width, (int)(rect.height/2));		
		}
		super.setBounds(new Rectangle(rect));
	}

	/**
	 * Use local coordinates.
	 * 
	 * @return true, if use local coordinates
	 */
	@Override
	protected boolean useLocalCoordinates(){return true;}
}